package org.example.intern.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.intern.config.exception.ServiceException;
import org.example.intern.entity.common.SysUser;
import org.example.intern.mapper.SysUserMapper;
import org.example.intern.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper,SysUser> implements ISysUserService {
    @Autowired
    private SysUserMapper sysUserMapper;


    @Override
    public SysUser findByUsername(String username) {
//        return sysUserMapper.findByUsername(username);
        return this.getOne(
                Wrappers.<SysUser>lambdaQuery()
                        .eq(SysUser::getUsername, username)
        ,false);
    }

    @Override
    public SysUser login(String username, String password) {
        SysUser user = this.findByUsername(username);
        if (user == null){
            throw new ServiceException("用户名不存在");
        }
        if (!user.getPassword().equals(password)) {
            throw new ServiceException("密码错误");
        }
        return user;
    }
}
